package com.qianfeng.xinyihezi.xinyihezi.adapter.adapter_meng;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.bean_meng.Address;

import java.util.List;

/**
 * Created by Administrator on 2016/11/16.
 */

public class AddressAdapter extends BaseAdapter {

    private List<Address> mList;
    private Context mContext;

    public AddressAdapter(List<Address> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(mContext, R.layout.list_address, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.mTextViewName.setText(mList.get(i).name);
        holder.mTextViewPhone.setText(mList.get(i).phone);
        holder.mTextViewAddress.setText(mList.get(i).area + mList.get(i).number);
        return view;
    }

    public static class ViewHolder {
        TextView mTextViewName;
        TextView mTextViewPhone;
        TextView mTextViewAddress;

        public ViewHolder(View view) {
            mTextViewName = (TextView) view.findViewById(R.id.tv_address_list_name);
            mTextViewPhone = (TextView) view.findViewById(R.id.tv_address_list_phone);
            mTextViewAddress = (TextView) view.findViewById(R.id.tv_address_list_area);
        }
    }
}
